<?php 
	$table_data = $this->table_data;
	$table_header = $this->table_header;
	$add_link = $this->add_link;
	$edit_link = $this->edit_link;
	$delete_link = $this->delete_link;
	$page = $this->page;
	$line_per_page = $this->line_per_page;
	$more_links = $this->more_links;
	$custom_fields = $this->custom_fields;	
	$counter = 0;
?>

<div id="table_wrapper">
	<?php include 'table_header.phtml';?>
	<table style="border-collapse: collapse;">
		<thead>
			<tr align="left" class="tr2">
				<?php foreach ($table_header as $key=>$value):?>
					<th id="<?php echo $value?>" width="200">
						<?php echo str_replace("_", " ", ucwords($this->translate($value)))?>
					</th>
				<?php endforeach;?>
				
				<?php if($custom_fields):?>
					<?php foreach ($custom_fields as $field):?>
						<th width="200"  align="center">
							<?php echo str_replace("_", " ", ucwords($this->translate($field['name'])))?>
						</th>		
					<?php endforeach;;?>
				<?php endif;?>
				
				<?php if($more_links):?>
					<?php foreach ($more_links as $link):?>
						<th width="200"  align="center">
							<?php echo str_replace("_", " ", ucwords($this->translate($link['name'])))?>
						</th>		
					<?php endforeach;;?>
				<?php endif;?>
				
				<th width="150" align="center">
					<?php echo $this->translate('Edit')?>
				</th>
				<th width="40" align="center">
					<?php echo $this->formCheckbox('del_ctrl', 1, array('onclick'=>'changeDeleteControl()'))?>
				</th>
			</tr>
		</thead>
		<tbody>
			<?php foreach ($table_data as $key=>$row):?>
			<tr id="row_<?php echo $row['id']?>" <?php echo ($counter ++) % 2 == 1 ? "class='tr4'" : "class='tr3'"?>">
				<?php foreach ($table_header as $header):?>
					<td width="200">
						<?php if ($header == 'picture'):?>
							<?php $picture = explode(',', $row[$header])?>
							<?php echo "<img width = '30px' src = '" . $picture[count($picture) - 1] . "'>"?>
						<?php elseif($header == 'description' || $header == "text"): ?>
							<?php echo substr($row[$header],0,100)?>
						<?php else: ?>
							<?php echo $row[$header]?>
						<?php endif;?>
					</td>
				<?php endforeach;?>
				
				<?php if($custom_fields):?>
					<?php foreach ($custom_fields as $field):?>
						<td width="200" align="center">
							<?php 
								$code = $field['code'];
								$code = str_replace("?", $row[$field['data_field']], $code);
								echo $code;
							?>
						</td>	
					<?php endforeach;?>
				<?php endif;?>
				
				<?php if($more_links):?>
					<?php foreach ($more_links as $link):?>
						<td width="200" align="center">
							<span class="generalLink">
								<a href="<?php echo $link['link']."$row[id]"?>">
									<?php echo $this->translate($link['name'])?>
								</a>
							</span>
						</td>	
					<?php endforeach;?>
				<?php endif;?>
				
				<td width="150" align="center">
					<div class="editLink" onclick="doRedirect('<?php echo $edit_link.'/edit_id/'.$row[id]?>')">
					</div>		
				</td>
				<td width="40" align="center">
					<?php echo $this->formCheckbox('del_ids[]', $row['id'], array('class'=>'delCheckbox'))?>
				</td>
			</tr>
			<?php endforeach;?>
		</tbody>
	</table>
	<?php include 'table_pager.phtml';?>
</div>

<div id="dialog-confirm" style="display:none;text-align: center;" title="Delete">
	<?php echo $this->translate("Are you sure to delete")?>
</div>

<div id="dialog-please-chose-item" style="display:none;text-align: center;" title="Chose an item">
	<?php echo $this->translate("Please chose an item")?>
</div>

<div id="dialog-delete-successful" style="display:none;text-align: center;" title="Delete">
	<?php echo $this->translate("Delete successful")?>
</div>